<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Edit_cp_lisensi extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('flexigrid');
        $this->load->library('flexigrid');
        $this->load->model('lisensi_model');
		$this->load->library('session');
		$this->load->library('form_validation');
		$this->cek_login();
    }

	
	function cek_login(){
		$id_hak = $this->session->userdata('id_hak');
		if($id_hak < 1 || $id_hak > 2 || $id_hak == ''){
			redirect ('login');
		}
		
	}
	
	function edit(){
		$data['title'] = 'Perbarui Data CP';
		$data['status'] = 'edit';
		
		$lisensi = $this->lisensi_model->selectone($this->session->userdata('id_lisensi'));
		foreach ($lisensi->result() as $row){
			$data['id_lisensi'] = $row->ID_LISENSI;
			$data['cp'] = $row->CP;
		}
        $this->template->write_view('header', 'template/header', $data);
        $this->template->write_view('content', 'lisensi/edit_cp', $data);
        $this->template->write_view('footer', 'template/footer', $data);
        $this->template->render();
	}


    //update peserta
    public function update($id) {
		if($this->cek_validasi() == false){
			$this->edit();
		}
		else{
			$data = array(
				'CP' => $this->input->post('cp'),
			);
			$this->lisensi_model->update_lisensi($id, $data);
			redirect('admin_home');
		}
    }
	
	
	
	function cek_validasi() {
        // Setting Rules
        $this->form_validation->set_rules('cp', 'Contact Person', 'required');

        //Setting Error Message
        $this->form_validation->set_message('required', 'Kolom %s harus diisi.');
        
        // Setting Delimiter
        $this->form_validation->set_error_delimiters('<li class="error">', '</li>');
        return $this->form_validation->run();
    }

}

/* End of file pegawai.php */
/* Location: ./application/controllers/pegawai.php */